		TITLE	SRCINST - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	MODULES

		PUBLIC	SRCNAME_INSTALL


		.DATA

		EXTERNDEF	SYMBOL_TEXT:BYTE

		EXTERNDEF	THEADR_HASH:DWORD,SYMBOL_LENGTH:DWORD,SRC_COUNT:DWORD,MOD_FIRST_SRC_GINDEX:DWORD
		EXTERNDEF	THEADR_HASH_TABLE_PTR:DWORD,MOD_LAST_SRC_GINDEX:DWORD

		EXTERNDEF	SRC_GARRAY:STD_PTR_S


		.CODE	PASS1_TEXT

		EXTERNDEF	CASE_STRING_COMPARE_HARD:PROC


INIT_SRCINST	PROC
		;
		;SAVE REGS, ZERO OUT HASH TABLE
		;
		MOV	EDI,EBX
		MOV	ECX,THEADR_HASH
		XOR	EAX,EAX
		REP	STOSD
		JMP	SRC_CONT

INIT_SRCINST	ENDP

SRCNAME_INSTALL	PROC
		;
		;DX IS HASH VALUE, CONVERT IT, TEXT IS IN SYMBOL_TEXT
		;ES MUST BE DGROUP
		;
		;RETURN AX IS GINDEX, DS:BX IS PHYSICAL
		;
		;DESTROYS ES,DS,DI,SI,DX,CX
		;
		PUSH	EBX
		MOV	EAX,MOD_FIRST_SRC_GINDEX

		MOV	EBX,THEADR_HASH_TABLE_PTR
		TEST	EAX,EAX

		PUSH	EDI
		JZ	INIT_SRCINST
SRC_CONT::
		MOV	EAX,EDX
		XOR	EDX,EDX

		MOV	EDI,EAX

		HASHDIV	THEADR_HASH

		PUSH	ESI
		MOV	EAX,DPTR [EBX+EDX*4]
		LEA	EBX,[EBX+EDX*4 -SRC_STRUCT._SRC_NEXT_HASH_GINDEX]
SRCNAME_NEXT:
		TEST	EAX,EAX
		JZ	DO_SRCNAME_INSTALL

		MOV	EDX,EAX			;SAVE LOGICAL IN EDX
		CONVERT	EAX,EAX,SRC_GARRAY
		ASSUME	EAX:PTR SRC_STRUCT
		MOV	EBX,EAX
		ASSUME	EBX:PTR SRC_STRUCT

		MOV	ECX,[EAX]._SRC_HASH	;CATCHES
		MOV	EAX,[EAX]._SRC_NEXT_HASH_GINDEX

		CMP	ECX,EDI
		JNZ	SRCNAME_NEXT
		;
		;HASH MATCHED, TRY ACTUAL TEXT COMPARE...
		;
		PUSH	EDI
		MOV	EDI,OFF SYMBOL_TEXT

		MOV	ECX,SYMBOL_LENGTH
		LEA	ESI,[EBX]._SRC_TEXT

		CALL	CASE_STRING_COMPARE_HARD

		POP	EDI
		MOV	EAX,[EBX]._SRC_NEXT_HASH_GINDEX

		JNZ	SRCNAME_NEXT

		MOV	EAX,EDX
		MOV	ECX,EBX

		POPM	ESI,EDI,EBX
		RET

DO_SRCNAME_INSTALL:
		;
		;EBX GETS POINTER...DI IS HASH
		;
		MOV	EAX,SYMBOL_LENGTH
		MOV	EDX,EDI

		ADD	EAX,SIZE SRC_STRUCT-3
		TILLP2_POOL_ALLOC		;EAX IS PHYS

		MOV	ESI,EBX
		MOV	EBX,EAX
		MOV	EDI,EAX

		INSTALL_POINTER_GINDEX	SRC_GARRAY

		MOV	[ESI].SRC_STRUCT._SRC_NEXT_HASH_GINDEX,EAX
		MOV	ESI,EAX			;SI IS NEW GINDEX

		MOV	ECX,SRC_STRUCT._SRC_TEXT/4
		XOR	EAX,EAX

		REP	STOSD

		MOV	ECX,SYMBOL_LENGTH
		MOV	[EBX]._SRC_HASH,EDX

		SHR	ECX,2
		MOV	EAX,ESI			;NEW GINDEX

		INC	ECX
		MOV	EDX,SRC_COUNT

		MOV	ESI,OFF SYMBOL_TEXT
		INC	EDX

		OPTI_MOVSD

		MOV	ECX,MOD_LAST_SRC_GINDEX
		MOV	SRC_COUNT,EDX

		OR	ECX,ECX
		JNZ	L4$

		MOV	MOD_FIRST_SRC_GINDEX,EAX
L5$:
		MOV	[EBX]._SRC_NUMBER,EDX

		MOV	MOD_LAST_SRC_GINDEX,EAX
		MOV	ECX,EBX

		POPM	ESI,EDI,EBX

		RET

L4$:
		CONVERT	ECX,ECX,SRC_GARRAY
		MOV	[ECX].SRC_STRUCT._SRC_NEXT_GINDEX,EAX
		JMP	L5$

SRCNAME_INSTALL	ENDP


		END

